
package org.apache.solr.search;

import org.apache.lucene.search.Query;

public class ExtendedQueryBase extends Query implements ExtendedQuery {

    private int cost;
    private boolean cache = true;
    private boolean cacheSep;

    @Override
    public void setCache(boolean cache) {
        this.cache = cache;
    }

    @Override
    public boolean getCache() {
        return cache;
    }

    @Override
    public void setCacheSep(boolean cacheSep) {
        this.cacheSep = cacheSep;
    }

    @Override
    public boolean getCacheSep() {
        return cacheSep;
    }

    @Override
    public void setCost(int cost) {
        this.cost = cost;
    }

    @Override
    public int getCost() {
        return cost;
    }

    public String getOptions() {

        StringBuilder sb = new StringBuilder();
        if (!cache) {
            sb.append("{!cache=false");
            sb.append(" cost=");
            sb.append(cost);
            sb.append("}");
        }
        else if (cacheSep) {
            sb.append("{!cache=sep");
            sb.append("}");
        }
        return sb.toString();
    }

    @Override
    public String toString(String field) {
        return getOptions();
    }
}
